/*appBar样式*/
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:frametrim/utility/screen.dart';
/*如果   hasBack的话必须要传入imgStr
*  使用时候需要用Scaffold包裹*/
@immutable
class AppbarCenterTitle extends StatelessWidget implements PreferredSizeWidget {
  final bool hasBack;
  final String title;
  final Color? titleColor;
  final Widget? rightWidget;
  final VoidCallback? onTap;
  final Color? backgroundColor;
  final bool? isCenterTitle;
  final double? titleSize;
  final double? height;
  final String? imgStr;

  AppbarCenterTitle(
      {Key? key,
      this.hasBack = true,
      required this.title,
      this.titleColor = Colors.white,
      this.rightWidget,
      this.onTap,
      this.imgStr,
      this.backgroundColor ,
      this.isCenterTitle = true,
      this.titleSize = 18,
      this.height = 45})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: backgroundColor!=null?backgroundColor:Colors.transparent,
      // color: Colors.white,
      width: Screen.width,
      height: height! + Screen.topSafeHeight,
      padding: EdgeInsets.fromLTRB(0, Screen.topSafeHeight, 0, 0),
      child: Stack(
        alignment: Alignment.center,
        children: [
          hasBack
              ? Positioned(
                  left: 0,
                  child: IconButton(
                      onPressed: () {
                        Navigator.pop(context);
                      },
                      icon: Container(
                        width: height,
                        height: height,
                        padding: EdgeInsets.fromLTRB(0, 8, 0, 8),
                        child: Image.asset(imgStr!),
                      )),
                )
              : Container(),
          isCenterTitle!
              ? Positioned(
                  child: Text(
                    title,
                    style: TextStyle(fontSize: titleSize, color: titleColor),
                  ),
                )
              : Positioned(
                  left: height!,
                  child: Text(
                    title,
                    style: TextStyle(fontSize: titleSize, color: titleColor),
                  )),
        ],
      ),
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(height!);
}
